/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.core.action.transaction;

import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.grayrabbit.pay.core.biz.manager.system.AppSystemManager;
import org.grayrabbit.pay.core.biz.manager.system.TradeTerminalManager;
import org.grayrabbit.pay.core.biz.manager.transaction.TradeHistoryManager;
import org.grayrabbit.pay.core.biz.manager.transaction.TradeRecordHistoryManager;
import org.grayrabbit.pay.core.model.entity.system.AppSystem;
import org.grayrabbit.pay.core.model.entity.system.TradeTerminal;
import org.grayrabbit.pay.core.model.entity.transaction.TradeHistory;
import org.grayrabbit.pay.core.model.entity.transaction.TradeRecordHistory;
import org.grayrabbit.pay.core.model.pages.PageList;
import org.grayrabbit.pay.core.model.results.GenericsResult;
import org.grayrabbit.web.struts2.GenericAction;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 
 * 
 * @author liyd
 * @version $Id: TradeRecordHistoryAction.java, v 0.1 Fri Jun 01 11:16:04 CST 2012 liyd Exp $
 */
@Results({
          @Result(name = GenericAction.RELOAD, location = "transaction/trade_record_history_list", type = "redirectAction"),
          @Result(name = GenericAction.INPUT, location = "transaction/trade_record_history-input.vm"),
          @Result(name = GenericAction.LIST, location = "transaction/trade_record_history-list.vm") })
@InterceptorRefs({ @InterceptorRef(value = "token", params = { "includeMethods", "save" }),
                  @InterceptorRef("login"), @InterceptorRef("defaultStack") })
public class TradeRecordHistoryAction extends GenericAction {

    /** serialVersionUID */
    private static final long            serialVersionUID   = 6564954084963562370L;

    /** 业务对象manager接口 */
    @Autowired
    private TradeRecordHistoryManager    tradeRecordHistoryManager;

    @Autowired
    private TradeHistoryManager          tradeHistoryManager;

    @Autowired
    private AppSystemManager             appSystemManager;

    @Autowired
    private TradeTerminalManager         tradeTerminalManager;

    /** 业务实体对象 */
    private TradeRecordHistory           tradeRecordHistory = new TradeRecordHistory();
    private TradeHistory                 tradeHistory       = new TradeHistory();

    /** 业务实体对象列表 */
    private PageList<TradeRecordHistory> tradeRecordHistoryList;
    private Map<String, AppSystem>       appMap;
    private Map<String, TradeTerminal>   terminalMap;

    /**
     * 根据trade_history_id查询交易变更历史记录列表
     * 访问URL /get_by_trade_history_id.action
     * @return
     */
    @Action(value = "get_by_trade_history_id")
    public String listByTradeId() {

        GenericsResult<PageList<TradeRecordHistory>> result = tradeRecordHistoryManager
            .queryPageList(tradeRecordHistory);
        GenericsResult<Map<String, AppSystem>> appResult = appSystemManager.findAllMap();
        GenericsResult<Map<String, TradeTerminal>> terminalResult = tradeTerminalManager
            .findAllMap();

        setTradeHistory(tradeHistoryManager.getById(tradeHistory.getTradeId()).getResultData());
        if (!result.isSuccess()) {
            this.addActionError(result.getResultMsg());
        }
        if (!appResult.isSuccess()) {
            this.addActionError(appResult.getResultMsg());
        }
        if (!terminalResult.isSuccess()) {
            this.addActionError(terminalResult.getResultMsg());
        }
        terminalMap = terminalResult.getResultData();
        appMap = appResult.getResultData();

        tradeRecordHistoryList = result.getResultData();
        return LIST;
    }

    /**
     * Getter method for property <tt>tradeRecordHistory</tt>.
     * 
     * @return property value of tradeRecordHistory
     */
    public TradeRecordHistory getTradeRecordHistory() {
        return tradeRecordHistory;
    }

    /**
     * Setter method for property <tt>tradeRecordHistory</tt>.
     * 
     * @param tradeRecordHistory value to be assigned to property tradeRecordHistory
     */
    public void setTradeRecordHistory(TradeRecordHistory tradeRecordHistory) {
        this.tradeRecordHistory = tradeRecordHistory;
    }

    /**
     * Getter method for property <tt>tradeRecordHistoryList</tt>.
     * 
     * @return property value of tradeRecordHistoryList
     */
    public PageList<TradeRecordHistory> getTradeRecordHistoryList() {
        return tradeRecordHistoryList;
    }

    /**
     * Setter method for property <tt>tradeRecordHistoryList</tt>.
     * 
     * @param districtList value to be assigned to property tradeRecordHistoryList
     */
    public void setTradeRecordHistoryList(PageList<TradeRecordHistory> tradeRecordHistoryList) {
        this.tradeRecordHistoryList = tradeRecordHistoryList;
    }

    public Map<String, AppSystem> getAppMap() {
        return appMap;
    }

    public void setAppMap(Map<String, AppSystem> appMap) {
        this.appMap = appMap;
    }

    public Map<String, TradeTerminal> getTerminalMap() {
        return terminalMap;
    }

    public void setTerminalMap(Map<String, TradeTerminal> terminalMap) {
        this.terminalMap = terminalMap;
    }

    public TradeHistory getTradeHistory() {
        return tradeHistory;
    }

    public void setTradeHistory(TradeHistory tradeHistory) {
        this.tradeHistory = tradeHistory;
    }

}
